<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@include file="../taglibs.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>商品详情</title>
<link rel="stylesheet" type="text/css" href="${path}/static/front/css/reset.css">
<link rel="stylesheet" type="text/css" href="${path}/static/front/css/main.css">

</head>
<body>

	<div class="header_con">
		<div class="header">
			<div class="welcome fl">欢迎来到天天生鲜!</div>
			
		<!-- 登录后：显示 欢迎谁谁，，，没登录：显示登录注册 -->
			<div class="fr">
		
 				<c:if test="${not empty user}">
					<div class="login_btn fl" >
						欢迎您：<em>${user.username}</em>
					</div>
					
					<div class="user_link fl">
						<span>|</span>
						<a href="user_center_info.html">用户中心</a>
						<span>|</span>
						<a href="${path}/cart/getCartListJsp.shtml">我的购物车</a>
						<span>|</span>
						<a href="user_center_order.html">我的订单</a>
					</div>
				</c:if>
				
				<c:if test="${empty user}">
   					<div class="login_btn fl">
						<a href="#" onclick="login()">登录</a>
						<span>|</span>
						<a href="register.html">注册</a>
					</div>  
				</c:if>
				
<%-- 				<c:choose>   
				  <c:when test="${empty user}">   
   					<div class="login_btn fl">
						<a href="login.html">登录</a>
						<span>|</span>
						<a href="register.html">注册</a>
					</div>   
				  </c:when>   
				  <c:otherwise> 
   					<div class="login_btn fl">  
				       	欢迎您：<em>${user.username}</em> 
				     </div> 
				  </c:otherwise>   
				</c:choose>    --%>
				
			</div>
			</div>
		</div>		
	</div>

	<div class="search_bar clearfix">
		<a href="index.html" class="logo fl"><img src="${path}/static/front/images/logo.png"></a>
		<div class="search_con fl">
			<input type="text" class="input_text fl" name="" placeholder="搜索商品">
			<input type="button" class="input_btn fr" name="" value="搜索">
		</div>
		<div class="guest_cart fr">
			<a href="${path}/cart/getCartListJsp.shtml" class="cart_name fl">购物车</a>
			<div class="goods_count fl" id="show_count">1</div>
		</div>
	</div>

	<div class="navbar_con">
		<div class="navbar clearfix">
			<div class="subnav_con fl">
				<h1>全部商品分类</h1>	
				<span></span>			
				<ul class="subnav">
					<li><a href="#" class="fruit">新鲜水果</a></li>
					<li><a href="#" class="seafood">海鲜水产</a></li>
					<li><a href="#" class="meet">猪牛羊肉</a></li>
					<li><a href="#" class="egg">禽类蛋品</a></li>
					<li><a href="#" class="vegetables">新鲜蔬菜</a></li>
					<li><a href="#" class="ice">速冻食品</a></li>
				</ul>
			</div>
			<ul class="navlist fl">
				<li><a href="">首页</a></li>
				<li class="interval">|</li>
				<li><a href="">手机生鲜</a></li>
				<li class="interval">|</li>
				<li><a href="">抽奖</a></li>
			</ul>
		</div>
	</div>

	<div class="breadcrumb">
		<a href="#">全部分类</a>
		<span>></span>
		<a href="#">新鲜水果</a>
		<span>></span>
		<a href="#">商品详情</a>
	</div>

	<div class="goods_detail_con clearfix">
		<div class="goods_detail_pic fl"><img width="350px" height="350px" src="/pic/${product.mainImage}"></div>

		<div class="goods_detail_list fr">
			<h3>${product.name}</h3>
			<p>${product.subtitle}</p>
			<div class="prize_bar">
				<span class="show_pirze">¥<em>${product.price}</em></span>
				<span class="show_unit">库存：${product.stock}</span>
			</div>
			<div class="goods_num clearfix">
				<div class="num_name fl">数 量：</div>
				<div class="num_add fl">
					<input type="text" class="num_show fl" id="quantity" value="1">
					<a href="javascript:;" class="add fr">+</a>
					<a href="javascript:;" class="minus fr">-</a>	
				</div> 
			</div>
			<div class="total">总价：<em>????元</em></div>
			<div class="operate_btn">
				<a href="javascript:;" class="buy_btn">立即购买</a>
				<a href="javascript:;" class="add_cart" id="add_cart">加入购物车</a>				
			</div>
		</div>
	</div>

	<div class="main_wrap clearfix">
		<div class="l_wrap fl clearfix">
			<div class="new_goods">
				<h3>新品推荐</h3>
				<ul>
					<li>
						<a href="#"><img src="${path}/static/front/images/goods/goods001.jpg"></a>
						<h4><a href="#">进口柠檬</a></h4>
						<div class="prize">￥3.90</div>
					</li>
					<li>
						<a href="#"><img src="${path}/static/front/images/goods/goods002.jpg"></a>
						<h4><a href="#">玫瑰香葡萄</a></h4>
						<div class="prize">￥16.80</div>
					</li>
				</ul>
			</div>
		</div>

		<div class="r_wrap fr clearfix">
			<ul class="detail_tab clearfix">
				<li class="active">商品介绍</li>
				<li>评论</li>
			</ul>

			<div class="tab_content">
				<dl>
					<dt>商品详情：</dt>
					<dd>${product.detail}</dd>
				</dl>
			</div>

		</div>
	</div>

	<div class="footer">
		<div class="foot_link">
			<a href="#">关于我们</a>
			<span>|</span>
			<a href="#">联系我们</a>
			<span>|</span>
			<a href="#">招聘人才</a>
			<span>|</span>
			<a href="#">友情链接</a>		
		</div>
		<p>CopyRight © 2016 北京天天生鲜信息技术有限公司 All Rights Reserved</p>
		<p>电话：010-****888    京ICP备*******8号</p>
	</div>
	
	<div class="add_jump"></div>
	
	<script src="${path}/static/common/jquery-2.1.4.js" type="text/javascript" charset="utf-8"></script>
    <script src="${path}/static/common/layer/layer.js" type="text/javascript" charset="utf-8"></script>
    <script src="${path}/static/common/mylayer.js" type="text/javascript" charset="utf-8"></script>
	<script type="text/javascript">
	
	/* 1.加入购物车   从sesstion取user,,如果空：没登录,滚去登陆; 如果有:已登录, 加进购物车*/
	$("#add_cart").on("click",function(){
		//1.从sesstion取user
		//2.判断 user == null?
			//2.1 null: 弹框 登录
			//2.2 !null: 加入购物车，跳转到购物车 页面
		
		var user = "${user}";
		if (user=="" || user==null) { //2.1说明没登录
			layer.open({
				type : 2,
				title : "登录",
				offset : "50px",
				area : ["370px", "380px"],
				//content : "${path}/webapp/WEB-INF/front/login.jsp"
				content : "${path}/user/getLoginJsp.shtml"
			});
		} else { //2.2.说明登陆了
			
			//0.发ajax请求，把添加购物测的商品 加入购物车cart数据库
			//1.url请求地址
			//2.参数：1.商品id。2.购买数量。3.userId 哪个用户买的 根据用户id分辨。
			
			$.post(
					"${path}/cart/insertCart.shtml",
					{"productId":"${product.id}", "quantity":$("#quantity").val(), "userId":"${user.id}", "checked":1},
					function(result) {
						if(result.success) {
							// 把 商品 插入 数据库的cart表
							mylayer.successMsg(result.msg);
						} else {
							mylayer.errorMsg(result.msg);
						}
					},
					"json"
				);
		}
		
		
	});
	
	
	/* 点击  右上方 的 登录 */
		function login() {
			layer.open({
				type : 2,
				tile : "添加",
				area : ["500px", "450px"],
				content : "${path}/user/getLoginJsp.shtml"
			});
		}
	
	
	
/* 页面自带的   就别给他 动了 */ /* 页面自带的   就别给他 动了 */ /* 页面自带的   就别给他 动了 */
		var $add_x = $('#add_cart').offset().top;
		var $add_y = $('#add_cart').offset().left;

		var $to_x = $('#show_count').offset().top;
		var $to_y = $('#show_count').offset().left;

		$(".add_jump").css({'left':$add_y+80,'top':$add_x+10,'display':'block'})
		$('#add_cart').click(function(){
			$(".add_jump").stop().animate({
				'left': $to_y+7,
				'top': $to_x+7},
				"fast", function() {
					$(".add_jump").fadeOut('fast',function(){
						$('#show_count').html(2);
					});

			});
		})
/* 页面自带的   就别给他 动了 */ /* 页面自带的   就别给他 动了 */ /* 页面自带的   就别给他 动了 */		 
		
		
	</script>
	
</body>
</html>